/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Entity.BaoCaoCongNo;
import Util.DatabaseHandle;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author Dark_Knight
 */
public class BaoCaoCongNoImpl implements BaoCaoCongNoDAO {

    public boolean add(BaoCaoCongNo data) {
        
        String sql = "{ call sp_BAOCAOCONGNO_add(?,?,?) }";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {   
            db.setOutParameter(1, java.sql.Types.INTEGER);
            db.setParameter(2, data.getThang());
            db.setParameter(3, data.getNam());
            
            db.executeStorePro();            
            data.setMaBaoCaoNo(db.getIntOutValue(1));            
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(BaoCaoCongNoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }        
    }

    public boolean delete(int MaBaoCaoCongNo) {
        String sql = "{ call sp_BAOCAOCONGNO_delete(?) }";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {
            
            db.setParameter(1, MaBaoCaoCongNo);
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(BaoCaoCongNoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
        
    }

    public boolean edit(BaoCaoCongNo data) {
        String sql = "{ call sp_BAOCAOCONGNO_edit(?,?,?) }";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {
            db.setParameter(1, data.getMaBaoCaoNo());
            db.setParameter(2, data.getThang());
            db.setParameter(3, data.getNam());
            
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(BaoCaoCongNoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

    public ResultSet getAll() {
        String sql = "{call sp_BAOCAOCONGNO_getllAll()}";
        DatabaseHandle db = new DatabaseHandle(sql, false);
        return db.excuteQuery();
    }    
}
